package com.openx.xoj.service.impl;

import com.openx.xoj.mapper.TitleMapper;
import com.openx.xoj.model.entity.Title;
import com.openx.xoj.service.TitleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TitleServiceImpl implements TitleService {

    private final TitleMapper titleMapper;

    @Autowired
    public TitleServiceImpl(TitleMapper titleMapper) {
        this.titleMapper = titleMapper;
    }

    @Override
    public List<Title> getAllTitles() {
        return titleMapper.selectList(null);
    }

    @Override
    public Title getTitleById(Long id) {
        return titleMapper.selectById(id);
    }

    @Override
    public boolean createTitle(Title title) {
        return titleMapper.insert(title) > 0;
    }

    @Override
    public boolean updateTitle(Title title) {
        return titleMapper.updateById(title) > 0;
    }

    @Override
    public boolean deleteTitle(Long id) {
        return titleMapper.deleteById(id) > 0;
    }
}
